<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\admin\model;

use think\Model;
use tree\Tree;

class UserModel extends Model
{

    protected $type = [
        'more' => 'array',
    ];

    public function adminUseTableTree($currentId = 0, $tpl = ''){
        $where = ['user_status' => 1];
//        if (!empty($currentCid)) {
//            $where['id'] = ['neq', $currentCid];
//        }
        $categories = $this->order("id ASC")->where($where)->select()->toArray();

        $tree       = new Tree();
        $tree->icon = ['&nbsp;&nbsp;│', '&nbsp;&nbsp;├─', '&nbsp;&nbsp;└─'];
        $tree->nbsp = '&nbsp;&nbsp;';



        $newCategories = [];
        foreach ($categories as $item) {
            $item['checked'] =$currentId== $item['id'] ? "checked" : "";
            $item['parent_id'] =0;
            $item['user_login'] =$item['user_login']!=null?$item['user_login']:$item['mobile'];

            array_push($newCategories, $item);
        }

        $tree->init($newCategories);


        $treeStr = $tree->getTree(0, $tpl);

        return $treeStr;
    }
}